﻿using System;
using System.Globalization;
using System.Text;
using System.Web;

namespace MyAnt.TestHost.Web.Globe
{
    /// <summary>
    /// Summary description for GlobeJsonDataProvider
    /// </summary>
    public class GlobeJsonDataProvider : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            var sb = new StringBuilder();
            var first = true;
            sb.Append("[[\"1999\",[");
            var r = new Random();
            var d = 0.001;
            for (var lng = -180; lng <= 180; lng += 20)
            {
                for (var lat = -180; lat <= 180; lat += 20)
                {
                    //d = (r.NextDouble()*0.7);
                    d += 0.0001;
                    if (!first) sb.Append(",");
                    sb.Append(String.Format("{0},{1},{2}", lat, lng, d.ToString("0.00", CultureInfo.InvariantCulture)));
                    first = false;
                    if (lng == -180 || lng == 180) break;
                }
            }
            sb.Append("]]]");
            context.Response.ContentType = "application/json";
            context.Response.Write(sb.ToString());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}